//
//  QLMAddDeviceTopCell.m
//  Xiaomakuaixiu
//
//  Created by 龚碧容 on 2017/10/13.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "QLMAddDeviceTopCell.h"

@implementation QLMAddDeviceTopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)cartypeBtnAction:(UIButton *)sender {
//    NSLog(@"cartypeBtnAction");
    [_delegate pushSelectTypeAction];
}

- (void)timeSelectBtnAction:(UIButton *)sender {
    [_delegate timeSelectPickerAction];
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *identifiew=@"QLMAddDeviceTopCellId";
    QLMAddDeviceTopCell *cell=[tableView dequeueReusableCellWithIdentifier:identifiew];
    if (cell==nil) {
        cell=[[[NSBundle mainBundle] loadNibNamed:@"QLMAddDeviceTopCell" owner:nil options:nil] firstObject];
        
        for (int i=1; i<3; i++) {
            UIView *line1=[[UIView alloc] initWithFrame:CGRectMake(20, 49.5*i, kScreen_width-20, 0.5)];
            line1.backgroundColor=[UIColor lightGrayColor];
            [cell addSubview:line1];
        }

        NSArray *titlArr=[NSArray arrayWithObjects:@"设备 *",@"别名",@"出厂日期",nil];
        for (int i=0; i<3; i++) {
            UILabel *aTipLabel=[[UILabel alloc] initWithFrame:CGRectMake(20, 10+50*i, 70, 30)];
            aTipLabel.font=[UIFont systemFontOfSize:16];
            aTipLabel.textColor=[UIColor darkGrayColor];
            
            if (i==0) {
                NSString *telStr=[NSString stringWithFormat:@"%@",titlArr[i]];
                NSMutableAttributedString *aString=[[NSMutableAttributedString alloc] initWithString:telStr];
                [aString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, telStr.length-2)];
                aTipLabel.attributedText=aString;
            }else{
                aTipLabel.text=titlArr[i];
            }
            
            aTipLabel.backgroundColor=[UIColor clearColor];
            aTipLabel.textAlignment=NSTextAlignmentLeft;
            [cell addSubview:aTipLabel];
        }
        
    }
    return cell;
}

- (void)_creatButtonMainUI{
    
    _selectCarTypeBtn=[self _creatButtonWithFrame:CGRectMake(90, 10, kScreen_width-10-90, 30) andTitle:@"请选择设备型号"];
    [_selectCarTypeBtn addTarget:self action:@selector(cartypeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    _selectCarTypeBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [self addSubview:_selectCarTypeBtn];
    
    UITextField *_textField=[[UITextField alloc] initWithFrame:CGRectMake(90, 50+10, kScreen_width-90-20, 30)];
    _textField.placeholder=@"请输入别名";
    _textField.font=[UIFont systemFontOfSize:16];
    _textField.backgroundColor=[UIColor clearColor];
    _textField.textColor=[UIColor darkGrayColor];
    _textField.clearButtonMode=UITextFieldViewModeWhileEditing;
    [self addSubview:_textField];
    _othernameTF=_textField;
    
    _timeSelectBtn=[self _creatButtonWithFrame:CGRectMake(90, 100+10, kScreen_width-90-20, 30) andTitle:@"请选择日期"];
    [_timeSelectBtn addTarget:self action:@selector(timeSelectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    _timeSelectBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [self addSubview:_timeSelectBtn];
}

- (UIButton *)_creatButtonWithFrame:(CGRect)aFrame andTitle:(NSString *)title{
    UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
    newButton.frame=aFrame;
    newButton.titleLabel.font=[UIFont systemFontOfSize:16];
    [newButton setTitle:title forState:UIControlStateNormal];
    [newButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    newButton.backgroundColor = [UIColor clearColor];
    return newButton;
}

@end
